<template>
	<view class="">
		<!--  -->
		<ben></ben>
		<!--  -->
		<view class="head_back posabs zin-1 wth100" style="top: 0;">

		</view>
		<view class="min30 pad20 background_f rad2 column">
			<view class="row">
				<view class="size30 col0 flex1 text_center" :class="tabIndex == tabindex ? 'font700' : 'font500'"
					v-for="(tabitem,tabindex) in tabList" :key="tabindex" @click="onTab(tabindex)">
					{{ tabitem }}
					<view class="mintop10" :class="tabIndex == tabindex ? 'box rad2 minau' : ''">
					</view>
				</view>
			</view>
			<view v-if="list.length != 0">
				<view class="column mintop30 padbottom20 border_bottom" v-for="item in list">
					<view class="row font500 size26 col9">
						<view class="">
							{{ item.order_no }}
						</view>
						<!-- <view class="" v-if="tabIndex == 2">
							充值时间
						</view> -->
						<view class="minau minright0">
							{{ item.create_time }}
						</view>
					</view>
					<view class="row font500 size30 col0 mintop20">
						<view class="" v-if="tabIndex == 0">
							积分抵扣￥{{ item.score }}
						</view>
						<view class="" v-if="tabIndex == 1">
							获得
						</view>
						<view class="" v-if="tabIndex == 2">
							充值
						</view>
						<view class="minau minright0" style="color: #FE3C3C;">
							{{ tabIndex == 0 ? '-' : '+' }}{{ item.score ? item.score : 0 }}
						</view>
					</view>
				</view>
				<view style=""><u-loadmore :status="status" /></view>
			</view>
			<view class="empty minbottom40 mintop40" v-else>
				<u-empty mode="data" icon="https://cdn.uviewui.com/uview/empty/data.png">
				</u-empty>
			</view>
		</view>
		<view style="height: 10rpx;">

		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				type: '',
				tabIndex: 0,
				page: 1,
				status: 'nomore',
				loadmore: [],
				list: [],
				tabList: ['积分使用', '获得积分', '充值积分']
			}
		},

		onLoad() {
			this.type = uni.getStorageSync('user_type');
		},
		onShow() {
			//当前页面展示的时候他就执行该生命周期
			const token = uni.getStorageSync('token');
			this.user_id = uni.getStorageSync('user_id');
			if (token) {
				//如果存在token
				this.getSore()
				//按正常逻辑来讲 登录成功 我们是不是需要向服务器获取用户的信息？
				//那么我们一起来获取用户信息
			} else {

				uni.showToast({
					title: '您还未登录，正在前往登录',
					icon: 'none'
				})
				setTimeout(function() {
					uni.navigateTo({
						url: "/mypackage/user/login"
					})
				}, 1000)
			}
		},
		onReachBottom() {
			if (this.page < 0) return;
			this.status = 'loading';
			this.page = ++this.page
			this.getSore()
			setTimeout(() => {
				console.log(this.loadmore);
				if (this.loadmore.length == 0) this.status = 'nomore';
				else this.status = 'loading';
			}, 1000)
		},
		methods: {
			onTab(i) {
				this.tabIndex = i
				this.getSore()
			},
			async getSore() {
				let {
					code,
					message,
					data
				} = await this.$com.fetchGet("member/sore_details/" + this.user_id, {
					is_type: this.type == 3 ? 2 : 1,
					type: this.tabIndex == 0 ? 2 : this.tabIndex == 1 ? 3 : 1,
					page: this.page
				})
				if (code == 200) {
					if (this.page != 1) {
						this.loadmore = data.items
						for (var i = 0; i < data.items.length; i++) {
							this.list.push(data.items[i]); // 加载的数据追加在上一页后面
						}
					} else {
						this.loadmore = data.items
						this.list = data.items
					}
				} else if (code == 500) {
					this.list = data
					this.loadmore = data
				} else {
					console.log(message);
				}
			}
		}
	}
</script>

<style scoped lang="less">
	.head_back {
		height: 300rpx;
		background-image: linear-gradient(120deg, #ff5a58 0%, #ff7e3f 100%);
		border-bottom-left-radius: 50%;
		border-bottom-right-radius: 50%;
	}

	.box {
		background-color: #FE9110;
		width: 140rpx;
		height: 10rpx;
	}

	.border_bottom {
		border-bottom: 2rpx solid #E7E7E7;

		&:nth-last-child(1) {
			border-bottom: 0;
		}
	}
</style>